package com.another.bidservice.controller;

import com.another.bidservice.entity.TStatic;
import com.another.bidservice.service.IStaticService;
import com.another.common.utils.common.MyException;
import org.apache.log4j.Logger;
import com.another.common.utils.result.Result;
import com.another.common.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/static")
@CrossOrigin
public class StaticController {

    private Logger logger=Logger.getLogger(this.getClass());

    @Autowired
    private IStaticService iStaticService;

    @PostMapping(value = "/getList")
    @ResponseBody
    public Result getList(@RequestBody TStatic tStatic) {
       try {
            return iStaticService.getList(tStatic);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteList")
    @ResponseBody
    public Result deleteList(@RequestBody List<Integer> rowids) {
        try {
            return iStaticService.deleteList(rowids);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertList")
    @ResponseBody
    public Result insertList(@RequestBody List<TStatic> tStatics) {
        try {
            return iStaticService.insertList(tStatics);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/updateList")
    @ResponseBody
    public Result updateList(@RequestBody List<TStatic> tStatics) {
        try {
            return iStaticService.updateList(tStatics);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
    
    @PostMapping(value = "/updateStatic")
    @ResponseBody
    public Result updateStatic(@RequestBody TStatic tStatic) {
        try {
            return iStaticService.updateStatic(tStatic);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertStatic")
    @ResponseBody
    public Result insertStatic(@RequestBody TStatic tStatic) {
        try {
            return iStaticService.insertStatic(tStatic);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteStatic")
    @ResponseBody
    public Result deleteStatic(@RequestBody TStatic tStatic) {
        try {
            return iStaticService.deleteStatic(tStatic);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    /**
     * @param tStatic
     * @return com.another.exhibitioncommon.utils.result.Result
     * @author Another
     * @description :  获取状态
     * @date 2020/3/17 9:54:20
     * @version : 1.0
     */
    @PostMapping(value = "/publicStatus")
    @ResponseBody
    public Result publicStatus(@RequestBody TStatic tStatic) {
        try {
            return iStaticService.publicStatus(tStatic);
        } catch (MyException me) {
            logger.info(me.getMessage(), me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(), e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

}



